#include <stdio.h>
char a[10];
int ctoi(char ch)
{
if(ch >= 'a') return (10 + ch -'a');
return ch - '0';
}
//将十进制的正整数n转换成base进制
void decimal(int n, int base)
{
int r, i = 0;
char c;
if(n < 16) printf("0");
do {
r = n % base;
c = r < 10 ? (r + '0') : ('a' + r - 10);
a[i++] = c;
n = n / base;
} while (n);
while (i) printf("%c", a[--i]);
}
void dd2hex(char *s)
{
char *p, *q;
int i, n, count;
n = 0;
p = q = s;
printf("0x");
while(*q && *p) {
while(*q != '.' && *q) q++;
count = q - p;
for(i = 0; i < count; i++) { n = n * 10 + ctoi(*p);p++;
}
decimal(n, 16);
if(*q) { q++;p = q;
}
n = 0;
}
printf("\n");
}
int main(int argc,char *argv[])
{
dd2hex(argv[1]);
return 0;
} 
